1140D - Minimum Triangulation - CodeForces Solution


dp greedy math *1200

Please click on ads to support us..

Python Code:

n = int(input())
ans = 0
for i in range(n-2):
    ans+=(i+2)*(i+3)
print(ans)

C++ Code:

 #include <iostream>
#include <string>
#include<stack>
#include<unordered_set>
#include<queue>
#include<deque>
#include<algorithm>
#include <cmath>
#include<ctime>
#include<map>
#include<set>
#include<vector>
#include<iomanip> // setprecision(number)   cout << fixed << setprecision(6);
#include<ctype.h> //  towlower toupper
#define sa(a,n) sort(a,a+n)
#define endl   "\n"
#define ll long long
#define tt int
#define str string
#define fs(n)              fixed<<setprecision(n)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define leadzero(a) __builtin_clz(a)        // count leading zeroes
#define trailzero(a) __builtin_ctz(a)       // count trailing zeroes
#define bitcount(a) __builtin_popcount(a)   // count set bits
using namespace std;
ll prime[10000005];
void  sieve() {
    for (ll x = 2; x < 1e7; x++)
    {
        if(x!=2&&x%2!=0)
            prime[x] = 1;
    }
    for (ll x = 3; x * x < 1e7; x += 2) 
    {
        if (prime[x]) 
        {
            for (int j = x * x; j < 1e7; j += x + x)
                prime[j] = 0;
        }
    }
}
bool isPrime(ll n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (ll i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
 
    return true;
}
ll lcm(ll x,ll y)
{
    return x * y / __gcd(x, y);
}
bool cm  (pair< int,string>p1  ,pair< int,string>p2)
 {
     if(p1.first==p2.first)
     return p1.second<p2.second;

      return p1.first>p2.first;
     
 }
 
 
// auto  it  = maxx.end(); it--; k=*it erase(it) ,, set<ll,greater<>>s;
//getline(cin, s1)
//auto it=upper_bound(v.begin(),v.end(),m);
int main() {
    fast;
    ll n,sum=0;
    cin>>n;
    for(ll x=2;x<n;x++)
        sum+=(x*(x+1));
        
       cout << sum;
}
  


Comments

Submit
0 Comments
More Questions

237. Delete Node in a Linked List
27. Remove Element
39. Combination Sum
378. Kth Smallest Element in a Sorted Matrix
162. Find Peak Element
1529A - Eshag Loves Big Arrays
19. Remove Nth Node From End of List
925. Long Pressed Name
1051. Height Checker
695. Max Area of Island
402. Remove K Digits
97. Interleaving String
543. Diameter of Binary Tree
124. Binary Tree Maximum Path Sum
1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
501A - Contest
160A- Twins
752. Open the Lock
1535A - Fair Playoff
1538F - Interesting Function
1920. Build Array from Permutation
494. Target Sum
797. All Paths From Source to Target
1547B - Alphabetical Strings
1550A - Find The Array
118B - Present from Lena
27A - Next Test
785. Is Graph Bipartite
90. Subsets II
1560A - Dislike of Threes